package paper.parse;

import paper.token.TT;
import paper.token.Token;

class HMArrow {
    TT match, out;
    int probsIndex;
    HMMatch goTo;
    boolean endOfLine;
    int outFlags;

    HMArrow(TT m, TT out, HMMatch next) {
        this.match = m;
        this.out = out;
        this.goTo = next;
        probsIndex = m.intValue();  // returns -1 if not bayesian
    }

    public Parse buildParse(Token t) {
//        System.out.println("TT " + t.t + " " + match +" " + probsIndex);
        if (probsIndex == -1) {        // not a bayesian match
            if (match == t.t) {
                return new Parse(0.99, out, t); // fixme
            } else if (t.t == TT.DOT) {
                return new Parse(0.001, out, t); // fixme
            } else if (t.t == TT.TITLE || t.t == TT.AUTHOR || t.t == TT.AFFILIATION || t.t == TT.WHERE) {
//                System.out.println("Odds of that " + t.t + " is a " + match + " are " + (1-t.probs[t.t.intValue()])/3);
                return new Parse((1-t.probs[t.t.intValue()])/3, out, t); // fixme
            } else {
//                System.out.println("HELLLLO ;;;;;; " + t);
                return new Parse(0.09, out, t); // fixme
            }
        }
        if (t.probs == null) {
            if (t.t == TT.DOT) {
                return new Parse(0.001, out, t); // fixme
            }
            return new Parse(0.1, out, t);
        } else {
//            System.out.println("TT " + t.t + " " + t.probs[probsIndex]);
            return new Parse(t.probs[probsIndex], out, t);
        }
    }
}
